Strict

Import mojo
Import agfx



Class TNgon Extends TPrimitive
	
	Field type:Int = -1
	
	Method New()
		Super.New(PRIMITIVE_TYPE_NGON)
	End Method
	
	
	Method Create:Void(c:TVector2,radius:Float,segments:Int)
	
		
		
		Local dir:TVector2 = New TVector2(0,1)		
		
		Local seg_angle:Float = 360.0 / segments
		
		
		For Local i:Int = 0 To segments-1
			
			Local pos:TVector2 = VecRotate(dir,i*seg_angle)
			pos.Mult(radius)
			pos.Add(c.x,c.y)
			Local vP:TVector2 =  New TVector2( pos.x,pos.y)			
			Self.AddPoint(vP)
			
		Next
		
	End Method
	
	Method ToString:String()
		Local res:String = ""
		For Local p:TVector2 = EachIn Self.points
			res = res + "|"+ p.ToString()
		Next
		Return res
	End Method
	
	Method Update:Void(recalc_center:Bool=True,recalc_bbox:Bool=True,recalc_edge:Bool=True)
		
		If recalc_edge Then Self.CalcEdges()
		If recalc_center Then Self.CalcCenter()
		If recalc_bbox Then Self.CalcBoundingBox()
		
	End Method
	
End Class